<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="../../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!doctype html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=emulateIE7"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta charset="utf-8">
    <link rel="stylesheet" href="${ctx}/css/sapar.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common.css"/>
    <link href="${ctx}/css/select2.min.css" rel="stylesheet" />
    <script type="text/javascript" src="${ctx}/js/jquery.js"></script>
    <script type="text/javascript" src="${ctx}/js/sapar.js"></script>
    <script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
    <script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
    <script type="text/javascript" src="${ctx}/js/kkpager.min.js"></script>
    <script type="text/javascript" src="${ctx}/js/mask.js"></script>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/kkpager_blue.css"/>
    <script type="text/javascript" src="${ctx}/assets/laydate/laydate.js"></script>
    <title>新增一个包</title>
    <style type="text/css">
        .kv-item label {
            width: 90px;
        }

        #suoyouqixie {
            width: 98%;
            height: auto;
            border: 1px solid blue;
            line-height: 30px;
        }

        #tijiao {
            width: 70px;
            height: 50px;
            background-color: green;
            color: white;
        }

        .shushu {
            color: green;
            font-weight: bold;
            text-align: center;
        }

        #mm {
            width: 100px;
        }
    </style>

</head>
<body>
<div id="mask" class="mask"></div>
<div id="saper-container">
    <div id="saper-hd"></div>
    <div id="saper-bd">
        <div class="subfiled clearfix">
            <h2>新建包</h2>
        </div>
        <form class="saper-form" id="dataForm">
            <div class="subfiled-content">
                <div class="tab-container" data-trigger="click">
                    <div class="tab">
                        <a href="javascript:;" class="current">基本信息</a>
                        <a href="javascript:;" id="xiangxi">器械</a>
                    </div>
                    <div class="tab-content">
                        <div class="tab-content-item">
                            <div class="kv-item clearfix">
                                <label ><span class="impInfo">*</span>包名：</label>
                                <div class="kv-item-content">
                                    <input type="text" placeholder="包名" name="packageName" id="baoming" value="${muban.packageName}">
                                </div>
                            </div>
                            <div class="kv-item clearfix">
                                <label ><span class="impInfo"></span>包大小：</label>
                                <div class="kv-item-content">
                                    <input type="text" placeholder="包大小" name="packageSize" id="baodaxiao"
                                           value="${muban.packageSize}">
                                </div>
                            </div>
                            <div class="kv-item clearfix">
                                <label ><span class="impInfo"></span>价格：</label>
                                <div class="kv-item-content">
                                    <input type="text" placeholder="价格" name="packagePrice" id="baojiage"
                                           value="${muban.packagePrice}"  >
                                </div>
                            </div>
                            <div class="kv-item clearfix">
                                <label ><span class="impInfo"></span>成本费：</label>
                                <div class="kv-item-content">
                                    <input type="text" placeholder="成本费" name="packageChengben" id="chengben">
                                </div>
                            </div>
                            <div class="kv-item clearfix">
                                <label ><span class="impInfo"></span>功能：</label>
                                <div class="kv-item-content">
                                    <input type="text" placeholder="功能" name="packageFunction" id="baogongneng" value="${muban.packageFunction}">
                                </div>
                            </div>
                            <div class="kv-item clearfix">
                                <label ><span class="impInfo">*</span>是否厂家包：</label>
                                <div class="kv-item-content">
                                    <select name="packageOutcategory" id="packageOutcategory" >
                                        <option value="0"  >否</option>
                                        <option value="1" >是</option>
                                        <%-- <c:if test="${qixieDicts != null }">
                                            <c:forEach items="${qixieDicts }" var="qixie">
                                                <c:if test="${qixie.dictId == 193 }">
                                                <option value="${qixie.dictId }">是</option>
                                                </c:if>
                                            </c:forEach>
                                        </c:if> --%>
                                    </select>
                                </div>
                            </div>
                            <div class="kv-item clearfix" id="needhide1">
                                <label ><span class="impInfo">*</span>所属科室：</label>
                                <div class="kv-item-content">
                                    <select name="packageDepartid" id="packageDepartid" onchange="hidediv()">
                                        <option value="">请选择</option>
                                        <c:if test="${depList != null}">
                                            <c:forEach items="${depList}" var="dep">
                                                <option value="${dep.departmentId}" <c:if test="${muban.packageDepartid==dep.departmentId}">selected='true'</c:if> >${dep.departmentName}</option>
                                            </c:forEach>
                                        </c:if>
                                    </select>
                                </div>
                            </div>
                            <div class="kv-item clearfix" id="needhide">
                                <label ><span class="impInfo">*</span>包属性 ：</label>
                                <div class="kv-item-content">
                                    <select name="packageCategory" id="packageCategory" onchange="hidediv2()">
                                        <option value="">请选择</option>
                                        <option value="1" <c:if test="${muban.packageCategory==0}">selected</c:if> >通用</option>
                                        <option value="0" <c:if test="${muban.packageCategory==1}">selected</c:if> >单封</option>
                                    </select>
                                </div>
                            </div>
                            <div class="kv-item clearfix">
                                <label ><span class="impInfo">*</span>外包装类型：</label>
                                <div class="kv-item-content">
                                    <select name="packageDaobaoId" id="packageDaobaoId">
                                        <option value="">请选择</option>
                                        <c:if test="${daolist != null}">
                                            <c:forEach items="${daolist}" var="dao">
                                                <option value="${dao.dabaoId}" <c:if test="${muban.packageDaobaoId==dao.dabaoId}">selected='true'</c:if> >${dao.dabaoName}</option>
                                            </c:forEach>
                                        </c:if>
                                    </select>
                                </div>
                            </div>
                            <div class="kv-item clearfix">
                                <label ><span class="impInfo">*</span>灭菌方式 ：</label>
                                <div class="kv-item-content">
                                    <select name="packageMiejunFangshi" id="packageMiejunFangshi">
                                        <option value="">请选择</option>
                                        <c:if test="${miejunFangshi != null}">
                                            <c:forEach items="${miejunFangshi}" var="miejunfangshi">
                                                <option value="${miejunfangshi.dictId}" <c:if test="${miejunfangshi.dictId==muban.packageMiejunFangshi}">selected</c:if>>${miejunfangshi.dictName}</option>
                                            </c:forEach>
                                        </c:if>
                                    </select>
                                </div>
                            </div>
                            <div class="kv-item clearfix">
                                <label ><span class="impInfo">*</span>审核类型：</label>
                                <div class="kv-item-content">
                                    <select name="packageMiejunNo" id="packageMiejunNo">
                                        <option value="1" <c:if test="${muban.packageMiejunNo==1}">selected</c:if> >化学监测审核</option>
                                        <option value="2" <c:if test="${muban.packageMiejunNo==2}">selected</c:if> >化学监测审核+生物监测审核</option>
                                    </select>
                                </div>
                            </div>
                            <div class="kv-item clearfix">
                                <label ><span class="impInfo">*</span>是否打印条码:</label>
                                <div class="kv-item-content">
                                    <select name="packagePrint" id="packagePrint">
                                        <option value="">请选择</option>
                                        <option value="0" <c:if test="${muban.packagePrint==0}">selected</c:if> >不打印</option>
                                        <option value="1" <c:if test="${muban.packagePrint==1}">selected</c:if> >打印</option>
                                    </select>
                                </div>
                            </div>
                            <div class="kv-item clearfix">
                                <label >是否打印科室:</label>
                                <div class="kv-item-content">
                                    <select name="packageUseno" id="packageUseno">
                                        <option value="">请选择</option>
                                        <option value="1" <c:if test="${muban.packageUseno==1}">selected</c:if> >不打印</option>
                                        <option value="0" <c:if test="${muban.packageUseno==0}">selected</c:if> >打印</option>
                                    </select>
                                </div>
                            </div>
                            <div class="kv-item clearfix">
                                <label >是否配包录入 ：</label>
                                <div class="kv-item-content">
                                    <select name="packageType" id="packageType">
                                        <option value="">请选择</option>
                                        <option value="0" <c:if test="${muban.packageType==0}">selected</c:if> >不录入</option>
                                        <option value="1" <c:if test="${muban.packageType==1}">selected</c:if> >录入</option>
                                    </select>
                                </div>
                            </div>
                            <div class="kv-item clearfix">
                                <label ><span class="impInfo"></span>生产时间：</label>
                                <div class="kv-item-content">
                                    <input type="datetime"
                                           onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" id="time"
                                           name="time" placeholder="生产时间" readonly="readonly">
                                </div>
                            </div>
                            <div class="kv-item clearfix">
                                <label ><span class="impInfo"></span>备注：</label>
                                <div class="kv-item-content">
                                    <input type="text" placeholder="备注" name="packageText">
                                </div>
                            </div>
                        </div>
                        <div class="tab-content-item">
                            <div id="table_left" class="table">
                                <!--表格操作-->
                                <div class="table">
                                    <!--表格操作-->
                                    <div class="table-operate ue-clear">
                                        <a href="javascript:;" class="add">添加器械</a>
                                    </div>
                                    <!--表格具体内容-->
                                    <div class="table-box">
                                        <table>
                                            <thead>
                                            <tr>
                                                <th class="text-left">物品编号</th>
                                                <th class="text-left">物品名称</th>
                                                <th class="text-left">物品速记码</th>
                                                <th class="text-left">物品尺寸</th>
                                                <th class="text-left">物品规格</th>
                                                <th class="text-left">物品功能</th>
                                                <th class="text-left">物品数量</th>
                                                <th class="text-left">删除</th>
                                            </tr>
                                            </thead>
                                            <tbody id="qixiebiao">
                                                <c:if test="${mingxiList !=null }">
                                                    <c:forEach items="${mingxiList}" var="data">
                                                        <tr id="${data.productId}" value="${data.productId}">
                                                            <td class="text-left">${data.productId}</td>
                                                            <td class="text-left">${data.productName}</td>
                                                            <td class="text-left">${data.product.productCode}</td>
                                                            <td class="text-left">${data.product.productSize}</td>
                                                            <td class="text-left">${data.product.productBarcode}</td>
                                                            <td class="text-left">${data.product.productFunction}</td>
                                                            <td class="text-left"><input type="text" size=5  class="shushu" name="packNum" value=${data.num}  /><input type="hidden" value=${data.productId} name="productId"></td>
                                                            <td class="text-left"><a href="javascript:;"  onclick="del( ${data.productId}  )">删除</a></td>
                                                        </tr>
                                                    </c:forEach>
                                                </c:if>

                                            </tbody>
                                        </table>
                                    </div>
                                </div><!--表格结束-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div id="saper-ft">
        <div class="buttons">
            <a href="javascript:;" class="sapar-btn sapar-btn-recom" id="savePackage">确认保存</a>
        </div>
    </div>
</div>
<script src="/js/select2.js" type = "text/javascript" ></script>
<script src="/js/pinyin.js" type = "text/javascript" ></script>
<script type="text/javascript">

    var type = ${type};
    $(function () {
        $(".add").click(function () {
            var selval = $("#packageOutcategory").val();
            layer.open({
                type: 2,
                title: '',
                maxmin: true,
                moveOut: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['700px', '540px'],
                content: "${ctx}/shoushumuban/qixieDetailList.do?changjia=" + selval
            });
        });

        $('select').select2();

        $("#savePackage").click(function () {
            var btn = true;
            var baoming = $("#baoming").val();
            var packageDepartid = $("#packageDepartid").val();
            var packageDaobaoId = $("#packageDaobaoId").val();
            var packageMiejunFangshi = $("#packageMiejunFangshi").val();
            var packagePrint = $("#packagePrint").val();
            var packageCategory = $("#packageCategory").val();
            var packageOutcategory = $("#packageOutcategory").val();
            var chengben = $("#chengben").val();
            var time = $("#time").val();
            if (isNullOrEmpty(baoming)) {
                alert("请输入包名");
                btn = false;
                return btn;
            }
            if ($("#needhide1").is(":hidden") && $("#needhide").is(":hidden")) {
                packageCategory = '';
//                packageDepartid = 17;
            }
            if ($("#needhide1").is(":hidden") && $("#needhide").is(":visible")) {
                //不可能
            }
            if ($("#needhide1").is(":visible") && $("#needhide").is(":hidden")) {
                packageCategory = '';
            }
            if ($("#needhide1").is(":visible") && $("#needhide").is(":visible")) {
                if (isNullOrEmpty(packageDepartid)) {
                    alert("请选择所属科室");
                    btn = false;
                    return btn;
                }
            }
            /* if(isNullOrEmpty(packageDepartid)){
             alert("请选择所属科室");
             btn=false;
             return btn;
             } */
            if (isNullOrEmpty(packageDaobaoId)) {
                alert("请选择外包装类型");
                btn = false;
                return btn;
            }
            if (isNullOrEmpty(packageMiejunFangshi)) {
                alert("请选择包灭菌方式");
                btn = false;
                return btn;
            }
            if (isNullOrEmpty(packagePrint)) {
                alert("是否打印明细");
                btn = false;
                return btn;
            }
            /* if(isNullOrEmpty(chengben)){
             alert("请输入成本费");
             btn=false;
             return btn;
             } */
            if ($("#needhide").is(":hidden")) {
                packageCategory = '';
            } else {
                /* if(isNullOrEmpty(packageCategory)){
                 alert("请选择包属性");
                 btn=false;
                 return btn;
                 } */
            }
            $(".shushu").each(function () {
                if ($(this).val() == '') {
                    btn = false;
                    layer.msg("数量不能为空");
                    return false;
                }
            });
            if (btn) {
                showMask();
                $.ajax({
                    type: "POST",
                    url: "${ctx}/shoushumuban/packageSave.do?time=" + time,
                    data: $('#dataForm').serialize(),// 你的formid
                    error: function (request) {
                        layer.alert("网络故障，请稍后再试!");
                    },
                    success: function (data) {
                        $("#mask").hide();
                        if (data.status == "true") {
                            layer.alert("保存成功", function () {
                                window.location.href = "${ctx}/shoushumuban/ssmubanList.do";
                            });
                        } else {
                            layer.msg(data.msg);
                        }
                    }
                });
            }
        });
    })

    <%--  回调函数--%>
    function callbackData(data) {
        console.log(data);
        var str = '';
        for (var i = 0; i < data.length; i++) {
            str += checkstr(data[i]);
        }
        $("#qixiebiao").append(str)
    }
    <%--拼接函数--%>
    function checkstr(data) {
        var obj = $("#" + data.productId);
        console.log("id:" + obj);
        <%--对于已经有的产品让他直接改数量--%>
        if (obj.length > 0) {
            //修改行之为数量 然后返回""
            layer.alert("已有" + data.productId + "这项，请直接修改数量");
            return "";
        } else {
            //console.log('<tr id="'+data.depId+'_'+data.packId+'"><td class="text-left">'+data.depVal+'</td><td class="text-left">'+data.packName+'</td><td class="text-left"><input type="hidden" name="packId" value="'+data.packId+'"/><input type="text"  class="gui-input" name="packNum"  id="'+data.packId+'" value="'+data.packNum+'"/></td><td><a href="javascript:;">删除</a>&nbsp;&nbsp;<a href="javascript:;" onclick="detail("'+data.packId+'")">查看明细</a></td></tr>');
            return '<tr id="' + data.productId + '" value="' + data.productId + '">'
                + '<td class="text-left">' + data.productId + '</td>'
                + '<td class="text-left">' + data.productName + '</td>'
                + '<td class="text-left">' + data.productCode + '</td>'
                + '<td class="text-left">' + data.productSize + '</td>'
                + '<td class="text-left">' + data.productBarcode + '</td>'
                + '<td class="text-left">' + data.productFunction + '</td>'
                + '<td class="text-left"><input type="text" size=5  class="shushu" name="packNum" value="'+data.num+'" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" /><input type="hidden" value="' + data.productId + '" name="productId"></td>'
                + '<td><a href="javascript:;"  onclick="del(\'' + data.productId + '\')">删除</a></td>'
                + '</tr>';
        }
    }

    function isNullOrEmpty(strVal) {
        strVal = strVal.replace(/(^\s*)|(\s*$)/g, "");
        if (strVal == '' || strVal == null || strVal == undefined) {
            return true;
        } else {
            return false;
        }
    }
    function hidediv() {
        var selvalue = $("#packageDepartid").val();
        var selvalue1 = $("#packageOutcategory").val();
        if (selvalue == 15 || selvalue1 != 0) {
            $("#needhide").hide("slow");
//    	packageCategory='';
        } else {
            $("#needhide").show("slow");
        }
    }
    function hidediv1() {
        var selvalue1 = $("#packageOutcategory").val();
        if (selvalue1 != 0) {
            $("#needhide").hide("slow");
            $("#needhide1").hide("slow");
//    	packageCategory='';
            //器械之显示厂家的器械
        } else {
            $("#needhide").show("slow");
            $("#needhide1").show("slow");
            //器械只显示医院的器械
        }
    }
    function hidediv2() {
        var selvalue = $("#packageCategory").val();
//    if(selvalue==1){
//    	$("#needhide1").hide("slow");
////    	packageCategory='';
//    }else{
//    	$("#needhide1").show("slow");
//    }
    }
    function del(id) {
        $("#" + id).remove();
    }
</script>
</body>
</html>